using System;
using System.Linq;
using System.Diagnostics.Contracts;

namespace FoundationLib.Mail 
{
	/// <summary>
	/// A data item which is a link to a URL.
	/// </summary>
	public class LinkMailDataItem : AtomicMailDataItem 
	{
		/// <summary>
		/// The link URL
		/// </summary>
		private string url;

		/// <summary>
		/// Creates a new link mail data item.
		/// </summary>
		/// <exception cref="ArgumentNullException">A null-reference was passed.
		/// </exception>
		/// <param name="key">The data item key</param>
		public LinkMailDataItem(string key) : base(key)
		{
		}

		/// <summary>
		/// Creates a new link mail data item.
		/// </summary>
		/// <exception cref="ArgumentNullException">A null-reference was passed.
		/// </exception>
		/// <param name="key">The data item key</param>
		/// <param name="value">The data item value</param>
		public LinkMailDataItem(string key, string value) : base(key, value)
		{
		}

		/// <summary>
		/// Creates a new link mail data item.
		/// </summary>
		/// <exception cref="ArgumentNullException">A null-reference was passed.
		/// </exception>
		/// <exception cref="ArgumentException">The URL is malformed.</exception>
		/// <param name="key">The data item key</param>
		/// <param name="value">The data item value</param>
		/// <param name="url">The link URL</param>
		public LinkMailDataItem(string key, string value, string url) : this(key, value)
		{
			Contract.Requires(!String.IsNullOrWhiteSpace(url));
			Contract.Requires(Uri.IsWellFormedUriString(url, UriKind.Absolute));
			this.url = url;
		}

		/// <summary>
		/// Gets or sets the link URL.
		/// </summary>
		/// <exception cref="ArgumentNullException">A null-reference was passed.</exception>
		/// <exception cref="ArgumentException">The URL is malformed.</exception>
		public string Url
		{
			get
			{
				return this.url;
			}
			set
			{
				Contract.Requires(!String.IsNullOrWhiteSpace(value));
				Contract.Requires(Uri.IsWellFormedUriString(value, UriKind.Absolute));
				this.url = value;
			}
		}

	}

}